<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>商品列表</h1>
<div>
    <table border="1">
        <tr>
            <th>商品id</th><th>商品标题</th>
            <th>商品价格</th><th>商品销量</th>
            <th>操作</th>
        </tr>
        <tr v-for="p in arr">
            <td>{{p.id}}</td><td>{{p.title}}</td>
            <td>{{p.price}}</td><td>{{p.sale_count}}</td>
            <td>
                <a href="javascript:void(0)" @click="del(p.id)">删除</a>
                <a :href="'/update.html?id='+p.id">修改</a>
            </td>
        </tr>
    </table>
    <input type="button" value="查看" @click="created()">
</div>
<script src="js/vue.js"></script>
<script src="js/axios.min.js"></script>
<script>
    let v=new Vue({
        el:"div",
        data:{
            arr:[]
        },
        methods:{
            created:function (){
                axios.get("/select").then(function (response) {
                    v.arr=response.data;
                })
            },
            del(id){
              axios.get("/delete?id="+id).then(function () {
                  alert("删除完成");
                  location.reload();
              })
            }
        }

    })
</script>
</body>
</html>